package cn.yunhe.action.temp;

import cn.yunhe.pojo.House;
import cn.yunhe.service.HouseService;
import cn.yunhe.util.BaseAction;
import com.opensymphony.xwork2.ModelDriven;

import java.util.ArrayList;
import java.util.List;

public class HouseAction2 extends BaseAction implements ModelDriven {
    private House house;
    private String target;
    private List<House> houseList=new ArrayList<>();


    private String hprice_range;
    private String hfloorage_range;
    private int street_district_did;
    private int street_sid;
    private int type_tid;


    HouseService houseService=new HouseService();

    /**
     * 插入
     * @return
     */
    public String insertHouse(){
        //receiveParameter2House(house);
        boolean flag=houseService.insertHouse(house);
        if (flag){
            return SUCCESS;
        }else {
            return ERROR;
        }
    }

    /**
     * 查询
     * @return
     */
    public String houseList(){
        house.getStreet().getDistrict().setDid(street_district_did);
        house.getStreet().setSid(street_sid);
        house.getType().setTid(type_tid);
        //核查接收的参数集合
        receiveParameter2House(house);
        houseList=houseService.houseList(house);
        target=SUCCESS;
        return target;
    }

    public House getHouse() {
        return house;
    }

    public void setHouse(House house) {
        this.house = house;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public List<House> getHouseList() {
        return houseList;
    }

    public void setHouseList(List<House> houseList) {
        this.houseList = houseList;
    }

    /**
     * 模型驱动,单级
     * @return
     */
    @Override
    public House getModel() {
        if (house==null)
            house=new House();
        return house;
    }

    /**
     * 测试使用
     *
     */
    public void receiveParameter2House(House house){
        System.out.println("hprice_range======="+hprice_range);
        System.out.println("hfloorage_range======="+hfloorage_range);
        System.out.println("street_district_did======="+street_district_did);
        System.out.println("street_sid======="+street_sid);
        System.out.println("type_tid======="+type_tid);
        System.out.println("==================Start==================");
        System.out.println("getHid======="+house.getHid());
        System.out.println("getHtitle======="+house.getHtitle());
        System.out.println("getHprice======="+house.getHprice());
        System.out.println("getHfloorage======="+house.getHfloorage());
        System.out.println("getHpubdate======="+house.getHpubdate());
        System.out.println("getHcontact======="+house.getHcontact());
        System.out.println("getHdesc======="+house.getHdesc());
        System.out.println("getHflag======="+house.getHflag());
        if (house.getType()!=null)
            System.out.println("getType().getTid()======="+house.getType().getTid());
            System.out.println("getType().getTname()======="+house.getType().getTname());
        if (house.getMember()!=null)
            System.out.println("getMember().getMid()======="+house.getMember().getMid());
            System.out.println("getMember().getMname()======="+house.getMember().getMname());
        if (house.getStreet()!=null)
            System.out.println("getStreet().getSid()======="+house.getStreet().getSid());
            System.out.println("getStreet().getSname()======="+house.getStreet().getSname());
        if (house.getStreet().getDistrict()!=null)
            System.out.println("getDistrict()======"+house.getStreet().getDistrict());
            System.out.println("getDistrict().getDid()======"+house.getStreet().getDistrict().getDid());
            System.out.println("getDistrict().getDname()======"+house.getStreet().getDistrict().getDname());
        System.out.println("===================End=================");
    }


    public String getHprice_range() {
        return hprice_range;
    }

    public void setHprice_range(String hprice_range) {
        this.hprice_range = hprice_range;
    }

    public String getHfloorage_range() {
        return hfloorage_range;
    }

    public void setHfloorage_range(String hfloorage_range) {
        this.hfloorage_range = hfloorage_range;
    }

    public int getStreet_district_did() {
        return street_district_did;
    }

    public void setStreet_district_did(int street_district_did) {
        this.street_district_did = street_district_did;
    }

    public int getStreet_sid() {
        return street_sid;
    }

    public void setStreet_sid(int street_sid) {
        this.street_sid = street_sid;
    }

    public int getType_tid() {
        return type_tid;
    }

    public void setType_tid(int type_tid) {
        this.type_tid = type_tid;
    }
}
